<div class="box-footer">
    {:token()}
    <div class="col-md-2">
    </div>
    <div class="col-md-8">
        <div class="btn-group pull-right">
            <button type="submit" class="btn flat btn-info pull-right dataform-sub">
                {$sub_title|default='保存'}
            </button>
        </div>
        <div class="btn-group pull-left">
            <button type="reset" class="btn flat btn-warning">重置</button>
        </div>
    </div>
</div>
<script src="__STATIC__/plugins/layer/layer.js"></script>
<script>
    var pre_url = "{$pre_url|default=''}";
    $(function () {
        $(".dataForm").submit(function (e) {
                    e.preventDefault();
                    var form_action = $(this).attr('action');
                    var form_method = $(this).attr('method');
                    var form_data = new FormData($(this)[0]);
                    console.log('%cajax submit start!', ';color:#333333');
                    console.log('action:' + form_action);
                    console.log('method:' + form_method);
                    console.log('data:' + form_data);
                    $.ajax({
                                url: form_action,
                                dataType: 'json',
                                type: form_method,
                                data: form_data,
                                async: false,
                                cache: false,
                                contentType: false,
                                processData: false,
                                success: function (result) {
                                    console.log('submit success!');
                                    if (result.code === 1) {
                                        console.log('%cresult success', ';color:#00a65a');
                                        layer.msg(result.msg);
                                        setTimeout(function () {
                                            goUrl(result.url);
                                        },500);
                                    } else {
                                        console.log('%cresult fail', ';color:#f39c12');
                                        layer.msg(result.msg);
                                    }
                                },
                                error: function (xhr, type, errorThrown) {
                                    //异常处理；
                                    console.log('%csubmit fail!', ';color:#dd4b39');
                                    console.log();
                                    console.log("type:" + type + ",readyState:" + xhr.readyState + ",status:" + xhr.status);
                                    console.log("url:" + form_action);
                                    console.log("data:" + form_data);
                                    layer.msg('访问错误');
                                }
                            }
                    );
                    return false;
                }
        );
    });

    function goUrl(url_data) {
        if (url_data.type !== undefined) {
            if(url_data.type===1){
                window.history.back();
            }else if(url_data.type===2){
                window.location.reload();
            }else if(url_data.type===3){
                window.location.href=url_data.url;
            }else if(url_data.type===4){
                console.log('不做任何操作');
            }else{
                console.log('位置跳转类型');
            }
        }
    }
</script>